<script setup lang="ts">
import { ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: "",
    name: "",
    title: "",
    adminEmail: "",
    connectionString: "",
    validUpto: new Date(),
    isActive: true,
    issuer: ""
  })
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-form-item label="租户编号" prop="id">
      <el-input
        v-model="newFormInline.id"
        clearable
        placeholder="请输入租户编号"
        :disabled="newFormInline.title !== '新增'"
      />
    </el-form-item>
    <el-form-item label="租户名称" prop="name">
      <el-input
        v-model="newFormInline.name"
        clearable
        placeholder="请输入租户名称"
        :disabled="newFormInline.title !== '新增'"
      />
    </el-form-item>

    <el-form-item label="管理员邮箱" prop="adminEmail">
      <el-input
        v-model="newFormInline.adminEmail"
        clearable
        placeholder="请输入管理员邮箱"
        :disabled="newFormInline.title !== '新增'"
      />
    </el-form-item>
     <el-form-item label="有效期" prop="validUpto" :disabled="newFormInline.title !== '新增'">
      <el-date-picker
        v-model="newFormInline.validUpto"
        type="datetime"
        value-format="YYYY-MM-DD HH:mm:ss"
        format="YYYY-MM-DD HH:mm:ss"
        placeholder="有效期"
      />
    </el-form-item>
    <el-form-item label="激活/冻结" prop="isActive">
      <el-radio-group v-model="newFormInline.isActive">
        <el-radio :label="true" :disabled="newFormInline.title !== '新增'">激活</el-radio>
        <el-radio :label="false" :disabled="newFormInline.title !== '新增'">冻结</el-radio>
      </el-radio-group>
    </el-form-item>

    <el-form-item label="数据库连接字符串" prop="connectionString">
      <el-input
        v-model="newFormInline.connectionString"
        clearable
        placeholder="请输入数据库连接字符串"
        type="textarea"
        :disabled="newFormInline.title !== '新增'"
      />
    </el-form-item>
    <el-form-item label="所有者" prop="issuer">
      <el-input
        v-model="newFormInline.issuer"
        clearable
        placeholder="请输入所有者"
        type="textarea"
        :disabled="newFormInline.title !== '新增'"
      />
    </el-form-item>
  </el-form>
</template>
